package com.example.myapplication;

import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

public class AsynTaskActivity extends AppCompatActivity {
  @Override protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.asyn_img_layout);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("异步任务加载图片");
    setSupportActionBar(toolbar);
    LoadImage();

  }

  @Override public boolean onCreateOptionsMenu(Menu menu) {
    menu.add(0, 1, 0, "返回上一级");

    return true;
  }

  @Override public boolean onOptionsItemSelected(@NonNull MenuItem item) {
    switch (item.getItemId()) {
      case 1:
        BackToLastLevel();
        break;

    }
    return true;
  }
  private void BackToLastLevel() {
    Intent intent = new Intent(this, BtnListenActivity.class);
    startActivity(intent);
  }
  private void LoadImage() {
    ImageView imageView = (ImageView) findViewById(R.id.ImgView);
    new ImageAsyncTask(imageView).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,"http://tiebapic.baidu.com/forum/w%3D580/sign=a8b17bfe1fafa40f3cc6ced59b65038c/57b74a90f603738d7236c0eef61bb051f919ec32.jpg?tbpicau=2023-05-24-05_6a700f0b4e2dfd7434f9e3468133d0cf");
  }
}
